home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / drag.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  7KB  |  330 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "font.h"
  13. #include "object.h"
  14. #include "paintop.h"
  15.  
  16. extern F_pos        last_position, new_position;  /* undo.c   */
  17. extern int        foreground_color, background_color;
  18. extern int        fix_x, fix_y, cur_x, cur_y;
  19.  
  20. extern            (*canvas_kbd_proc)();
  21. extern            (*canvas_locmove_proc)();
  22. extern            (*canvas_leftbut_proc)();
  23. extern            (*canvas_middlebut_proc)();
  24. extern            (*canvas_rightbut_proc)();
  25. extern            null_proc();
  26. extern            set_popupmenu();
  27.  
  28. static            draw_movingbox();
  29. static int        x1off, y1off, x2off, y2off;
  30.  
  31.             void (*return_proc)();
  32.              move_line(), place_line();
  33.              move_arc(), place_arc();
  34.              move_spline(), place_spline();
  35.              move_movingbox();
  36.              place_ellipse();
  37.              move_text(), place_text();
  38.              place_compound();
  39.  
  40. static F_arc        *arc;
  41. static F_compound    *compound;
  42. static F_ellipse    *ellipse;
  43. static F_line        *line;
  44. static F_spline        *spline;
  45. static F_text        *text;
  46.  
  47. static
  48. draw_movingbox(op)
  49. int    op;
  50. {
  51.     register int    x1, y1, x2, y2;
  52.  
  53.     x1 = cur_x + x1off;
  54.     x2 = cur_x + x2off;
  55.     y1 = cur_y + y1off;
  56.     y2 = cur_y + y2off;
  57.     pw_vector(canvas_pixwin, x1, y1, x1, y2, op, 1);
  58.     pw_vector(canvas_pixwin, x1, y2, x2, y2, op, 1);
  59.     pw_vector(canvas_pixwin, x2, y2, x2, y1, op, 1);
  60.     pw_vector(canvas_pixwin, x2, y1, x1, y1, op, 1);
  61.     }
  62.  
  63. move_movingbox(x, y)
  64. int    x, y;
  65. {
  66.     draw_movingbox(INV_PAINT);
  67.     cur_x = x;
  68.     cur_y = y;
  69.     draw_movingbox(INV_PAINT);
  70.     }
  71.  
  72. /***************************** ellipse section ************************/
  73.  
  74. init_ellipsedragging(e, x, y)
  75. F_ellipse    *e;
  76. int        x, y;
  77. {
  78.     ellipse = e;
  79.     last_position.x = cur_x = x; 
  80.     last_position.y = cur_y = y;
  81.     x1off = (e->center.x - e->radiuses.x) - cur_x; 
  82.     x2off = (e->center.x + e->radiuses.x) - cur_x; 
  83.     y1off = (e->center.y - e->radiuses.y) - cur_y;
  84.     y2off = (e->center.y + e->radiuses.y) - cur_y;
  85.     canvas_locmove_proc = move_movingbox;
  86.     canvas_middlebut_proc = place_ellipse;
  87.     set_action_on();
  88.     draw_movingbox(INV_PAINT);
  89.     }
  90.  
  91. place_ellipse(x, y)
  92. int    x, y;
  93. {
  94.     draw_movingbox(INV_PAINT);
  95.     new_position.x = x;
  96.     new_position.y = y;
  97.     translate_ellipse(ellipse, x - last_position.x, y - last_position.y);
  98.     pw_batch_on(canvas_pixwin);
  99.     draw_ellipse(ellipse, foreground_color);
  100.     pw_batch_off(canvas_pixwin);
  101.     show_pointmarker();
  102.     set_modifiedflag();
  103.     (*return_proc)();
  104.     }
  105.  
  106. /*****************************  arc  section  *******************/
  107.  
  108. init_arcdragging(a, x, y)
  109. F_arc    *a;
  110. int    x, y;
  111. {
  112.     arc = a;
  113.     fix_x = last_position.x = cur_x = x;
  114.     fix_y = last_position.y = cur_y = y;
  115.     canvas_locmove_proc = move_arc;
  116.     canvas_middlebut_proc = place_arc;
  117.     set_action_on();
  118.     draw_movingarc(arc, INV_PAINT);
  119.     }
  120.  
  121. move_arc(x, y)
  122. int    x, y;
  123. {
  124.     draw_movingarc(arc, INV_PAINT);
  125.     cur_x = x;  
  126.     cur_y = y;
  127.     draw_movingarc(arc, INV_PAINT);
  128.     }
  129.  
  130. place_arc(x, y)
  131. int    x, y;
  132. {
  133.     draw_movingarc(arc, INV_PAINT);
  134.     new_position.x = x;
  135.     new_position.y = y;
  136.     translate_arc(arc, x - fix_x, y - fix_y);
  137.     pw_batch_on(canvas_pixwin);
  138.     draw_arc(arc, foreground_color);
  139.     pw_batch_off(canvas_pixwin);
  140.     show_pointmarker();
  141.     set_modifiedflag();
  142.     (*return_proc)();
  143.     }
  144.  
  145. draw_movingarc(a, op)
  146. F_arc    *a;
  147. int    op;
  148. {
  149.     int    dx, dy;
  150.  
  151.     dx = cur_x - fix_x;
  152.     dy = cur_y - fix_y;
  153.     pw_vector(canvas_pixwin, a->point[0].x+dx, a->point[0].y+dy,
  154.         a->point[1].x+dx, a->point[1].y+dy, op, 1);
  155.     pw_vector(canvas_pixwin, a->point[1].x+dx, a->point[1].y+dy,
  156.         a->point[2].x+dx, a->point[2].y+dy, op, 1);
  157.     }
  158.  
  159. /*************************  line  section  **********************/
  160.  
  161. init_linedragging(l, x, y)
  162. F_line    *l;
  163. int    x, y;
  164. {
  165.     line = l;
  166.     last_position.x = cur_x = fix_x = x;
  167.     last_position.y = cur_y = fix_y = y;
  168.     canvas_locmove_proc = move_line;
  169.     canvas_middlebut_proc = place_line;
  170.     set_action_on();
  171.     draw_movingpoint(line->points, INV_PAINT);
  172.     }
  173.  
  174. move_line(x, y)
  175. int    x, y;
  176. {
  177.     draw_movingpoint(line->points, INV_PAINT);
  178.     cur_x = x;  
  179.     cur_y = y;
  180.     draw_movingpoint(line->points, INV_PAINT);
  181.     }
  182.  
  183. place_line(x, y)
  184. int    x, y;
  185. {
  186.     draw_movingpoint(line->points, INV_PAINT);
  187.     new_position.x = x;
  188.     new_position.y = y;
  189.     translate_line(line, x - fix_x, y - fix_y);
  190.     draw_line(line, PAINT);
  191.     show_pointmarker();
  192.     set_modifiedflag();
  193.     (*return_proc)();
  194.     }
  195.  
  196. draw_movingpoint(ps, op)
  197. F_point    *ps;
  198. int    op;
  199. {
  200.     F_point    *p;
  201.     int    dx, dy, x, y, xx, yy;
  202.  
  203.     dx = cur_x - fix_x;
  204.     dy = cur_y - fix_y;
  205.     p = ps;
  206.     x = p->x + dx;
  207.     y = p->y + dy;
  208.     for (p = p->next; p != NULL; x = xx, y = yy, p = p->next) {
  209.         xx = p->x + dx;  yy = p->y +dy;
  210.         pw_vector(canvas_pixwin, x, y, xx, yy, op, 1);
  211.         }
  212.     }
  213.  
  214. /************************  text section  **************************/
  215.  
  216. init_textdragging(t, x, y)
  217. F_text    *t;
  218. int    x, y;
  219. {
  220.     text = t;
  221.     fix_x = cur_x = x; 
  222.     fix_y = cur_y = y;
  223.     x1off = t->base_x - x;
  224.     y1off = t->base_y - y;
  225.     canvas_locmove_proc = move_text;
  226.     canvas_middlebut_proc = place_text;
  227.     draw_movingtext();
  228.     set_action_on();
  229.     }
  230.  
  231. move_text(x, y)
  232. int    x, y;
  233. {
  234.     draw_movingtext();
  235.     cur_x = x;
  236.     cur_y = y;
  237.     draw_movingtext();
  238.     }
  239.  
  240. place_text(x, y)
  241. int    x, y;
  242. {
  243.     draw_movingtext();
  244.     new_position.x = x;
  245.     new_position.y = y;
  246.     last_position.x = fix_x; 
  247.     last_position.y = fix_y;
  248.     translate_text(text, x - fix_x, y - fix_y);
  249.     draw_text(text, PAINT);
  250.     set_modifiedflag();
  251.     (*return_proc)();
  252.     }
  253.  
  254. draw_movingtext()
  255. {
  256.     pw_text(canvas_pixwin, cur_x+x1off, cur_y + y1off, INV_PAINT,
  257.         canvas_font, text->cstring);
  258.     }
  259.  
  260. /*************************  spline  section  **********************/
  261.  
  262. init_splinedragging(s, x, y)
  263. F_spline    *s;
  264. int        x, y;
  265. {
  266.     spline = s;
  267.     last_position.x = cur_x = fix_x = x;
  268.     last_position.y = cur_y = fix_y = y;
  269.     canvas_locmove_proc = move_spline;
  270.     canvas_middlebut_proc = place_spline;
  271.     set_action_on();
  272.     draw_movingpoint(spline->points, INV_PAINT);
  273.     }
  274.  
  275. move_spline(x, y)
  276. int    x, y;
  277. {
  278.     draw_movingpoint(spline->points, INV_PAINT);
  279.     cur_x = x;  
  280.     cur_y = y;
  281.     draw_movingpoint(spline->points, INV_PAINT);
  282.     }
  283.  
  284. place_spline(x, y)
  285. int    x, y;
  286. {
  287.     draw_movingpoint(spline->points, INV_PAINT);
  288.     translate_spline(spline, x - fix_x, y - fix_y);
  289.     new_position.x = x;
  290.     new_position.y = y;
  291.     pw_batch_on(canvas_pixwin);
  292.     draw_spline(spline, PAINT);
  293.     pw_batch_off(canvas_pixwin);
  294.     show_pointmarker();
  295.     set_modifiedflag();
  296.     (*return_proc)();
  297.     }
  298.  
  299. /*****************************  Compound section  *******************/
  300.  
  301. init_compounddragging(c, x, y)
  302. F_compound    *c;
  303. int        x, y;
  304. {
  305.     compound = c;
  306.     last_position.x = cur_x = x; 
  307.     last_position.y = cur_y = y;
  308.     x1off = c->nwcorner.x - x;
  309.     x2off = c->secorner.x - x;
  310.     y1off = c->nwcorner.y - y;
  311.     y2off = c->secorner.y - y;
  312.     canvas_locmove_proc = move_movingbox;
  313.     canvas_middlebut_proc = place_compound;
  314.     set_action_on();
  315.     draw_movingbox(INV_PAINT);
  316.     }
  317.  
  318. place_compound(x, y)
  319. int    x, y;
  320. {
  321.     draw_movingbox(INV_PAINT);
  322.     new_position.x = x;
  323.     new_position.y = y;
  324.     translate_compound(compound, x - last_position.x, y - last_position.y);
  325.     draw_compound(compound);
  326.     draw_compoundbox(compound, INV_PAINT);
  327.     set_modifiedflag();
  328.     (*return_proc)();
  329.     }
  330.